package com.spm.librarianmanagersystem.service.impl;

import com.spm.librarianmanagersystem.mapper.BorrowMapper;
import com.spm.librarianmanagersystem.mapper.FineMapper;
import com.spm.librarianmanagersystem.mapper.UserManageMapper;
import com.spm.librarianmanagersystem.pojo.Borrow;
import com.spm.librarianmanagersystem.pojo.Fine;
import com.spm.librarianmanagersystem.service.DeleteService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeleteServiceImpl implements DeleteService {

    @Autowired
    private UserManageMapper userManageMapper;

    @Autowired
    private FineMapper fineMapper;

    @Autowired
    private BorrowMapper borrowMapper;

    @Override
    public boolean deleteUser(Integer user_id) {

        List<Fine> fines = fineMapper.getFineByUserID(user_id);
        List<Borrow> borrows  = borrowMapper.getBorrowingListByUserId(user_id);

        if (fines.isEmpty() && borrows.isEmpty()) {
            userManageMapper.deleteFine((Integer) user_id);
            userManageMapper.deleteBorrow( (Integer) user_id );
            userManageMapper.deleteRes((Integer) user_id );
            userManageMapper.deleteMember((Integer) user_id);
            return true;
        } else {
            return false;
        }
    }
}
